package com.lb.jwitter.action;


import java.text.DateFormat; 
import java.text.SimpleDateFormat; 
import java.util.ArrayList; 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import java.util.Map; 
import org.springframework.test.context.ContextConfiguration; 
import com.lb.jwitter.service.TblQuyenChiTietService; 
import com.lb.jwitter.service.TblTaiKhoan; 
import com.opensymphony.xwork2.ActionContext; 
import java.util.Collection; 
import com.lb.jwitter.util.ApplicationContextProvider; 
import java.util.Date; 
import java.util.GregorianCalendar; 
import javax.xml.datatype.DatatypeFactory; 
import javax.xml.datatype.XMLGregorianCalendar; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 
import com.lb.jwitter.service.ConditionReport; 
import com.lb.jwitter.util.Message; 
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.TblQLDTTXAHocVienHocPhi;
import com.lb.jwitter.service.TblQLDTTXAHocVienHocPhiService;
import com.lb.jwitter.service.TblQLDTTXAHocVien;
import com.lb.jwitter.service.TblQLDTTXAHocVienService;

import com.lb.jwitter.service.TblQLDTTXAHocKyTrongNam;
import com.lb.jwitter.service.TblQLDTTXAHocKyTrongNamService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblQLDTTXAHocVienHocPhiUpdateAction{
    private int pageSize; 
    public int getPageSize() {
       return pageSize;
 }

    public void setPageSize(int pageSize) { this.pageSize = pageSize; }

    private int page; 
    public int getPage() { return page; }

    public void setPage(int page) { this.page = page; }

    private int pages; 
    public int getPages() { return pages; }

    public void setPages(int pages) { this.pages = pages; }

    private String dataString; 
    public String getDataString() { return dataString; }

    private Message msg; 
    public Message getMsg() { return msg; }

    private int id; 
    public int getId() {
       return id;
 }

    public void setId(int id) {
       this.id = id;
 }

    private int hocVienId; 
    public void setHocVienId(int hocVienId) {
       this.hocVienId = hocVienId;
 }

    public int getHocVienId() {
       return hocVienId;
 }

    private int hocKyId; 
    public void setHocKyId(int hocKyId) {
       this.hocKyId = hocKyId;
 }

    public int getHocKyId() {
       return hocKyId;
 }

    private int soMonHoc; 
    public void setSoMonHoc(int soMonHoc) {
       this.soMonHoc = soMonHoc;
 }

    public int getSoMonHoc() {
       return soMonHoc;
 }

    private int soMonHocDuocMien; 
    public void setSoMonHocDuocMien(int soMonHocDuocMien) {
       this.soMonHocDuocMien = soMonHocDuocMien;
 }

    public int getSoMonHocDuocMien() {
       return soMonHocDuocMien;
 }

    private int soTinChi; 
    public void setSoTinChi(int soTinChi) {
       this.soTinChi = soTinChi;
 }

    public int getSoTinChi() {
       return soTinChi;
 }

    private double tienHaTang; 
    public void setTienHaTang(double tienHaTang) {
       this.tienHaTang = tienHaTang;
 }

    public double getTienHaTang() {
       return tienHaTang;
 }

    private double hocPhi; 
    public void setHocPhi(double hocPhi) {
       this.hocPhi = hocPhi;
 }

    public double getHocPhi() {
       return hocPhi;
 }

    private double tienPhaiDong; 
    public void setTienPhaiDong(double tienPhaiDong) {
       this.tienPhaiDong = tienPhaiDong;
 }

    public double getTienPhaiDong() {
       return tienPhaiDong;
 }

    private int trangThai; 
    public void setTrangThai(int trangThai) {
       this.trangThai = trangThai;
 }

    public int getTrangThai() {
       return trangThai;
 }

    private TblQLDTTXAHocVienHocPhi tblQLDTTXAHocVienHocPhi; 
    public void setTblQLDTTXAHocVienHocPhi (TblQLDTTXAHocVienHocPhi tblQLDTTXAHocVienHocPhi) {
        this.tblQLDTTXAHocVienHocPhi = tblQLDTTXAHocVienHocPhi;
 }

    private Collection<TblQLDTTXAHocVienHocPhi> tblQLDTTXAHocVienHocPhis; 
    public void setTblQLDTTXAHocVienHocPhis(Collection<TblQLDTTXAHocVienHocPhi> tblQLDTTXAHocVienHocPhis) {
        this.tblQLDTTXAHocVienHocPhis = tblQLDTTXAHocVienHocPhis; 
      } 

    private TblQLDTTXAHocVienHocPhiService tblQLDTTXAHocVienHocPhiService; 

    private TblQLDTTXAHocVienService tblQLDTTXAHocVienService; 

    private TblQLDTTXAHocKyTrongNamService tblQLDTTXAHocKyTrongNamService; 

	private int preUpdate(Message msg, TblQLDTTXAHocVienHocPhi obj ){ 
        msg.setPreMessage_b(true); 
        msg.setPreMessage_s("success"); 
        return 1; 
    } 
	private int postUpdate(Message msg, TblQLDTTXAHocVienHocPhi obj ){ 
        msg.setPostMessage_b(true); 
        msg.setPostMessage_s("success"); 
        return 1; 
    } 
  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
    public String execute() throws Exception 
   { 
    try{ 
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_HocVien_HocPhi", "sua")){ 
        return "noprivilege"; 
    }
        tblQLDTTXAHocVienHocPhiService = (TblQLDTTXAHocVienHocPhiService) context.getBean("tbl_QLDTTXA_HocVien_HocPhiClient"); 
        tblQLDTTXAHocVienService = (TblQLDTTXAHocVienService) context.getBean("tbl_QLDTTXA_HocVienClient"); 

        tblQLDTTXAHocKyTrongNamService = (TblQLDTTXAHocKyTrongNamService) context.getBean("tbl_QLDTTXA_HocKyTrongNamClient"); 

        msg = new Message(); 
        tblQLDTTXAHocVienHocPhi = tblQLDTTXAHocVienHocPhiService.gettblQLDTTXAHocVienHocPhi(new Long(id)); 
        tblQLDTTXAHocVienHocPhi.setHocVienId(tblQLDTTXAHocVienService.gettblQLDTTXAHocVien(new Long(hocVienId))); 
        tblQLDTTXAHocVienHocPhi.setHocKyId(tblQLDTTXAHocKyTrongNamService.gettblQLDTTXAHocKyTrongNam(new Long(hocKyId))); 
        tblQLDTTXAHocVienHocPhi.setSoMonHoc(soMonHoc); 
        tblQLDTTXAHocVienHocPhi.setSoMonHocDuocMien(soMonHocDuocMien); 
        tblQLDTTXAHocVienHocPhi.setSoTinChi(soTinChi); 
        tblQLDTTXAHocVienHocPhi.setTienHaTang(tienHaTang); 
        tblQLDTTXAHocVienHocPhi.setHocPhi(hocPhi); 
        tblQLDTTXAHocVienHocPhi.setTienPhaiDong(tienPhaiDong); 
        if(trangThai == 1){ 
           tblQLDTTXAHocVienHocPhi.setTrangThai(true); 
       } else { 
           tblQLDTTXAHocVienHocPhi.setTrangThai(false); 
       } 
        preUpdate(msg,tblQLDTTXAHocVienHocPhi); 
       if (msg.isPreMessage_b()) 
       { 
           tblQLDTTXAHocVienHocPhiService.updatetblQLDTTXAHocVienHocPhi(tblQLDTTXAHocVienHocPhi); 
           postUpdate(msg, tblQLDTTXAHocVienHocPhi); 
           if (msg.isPostMessage_b() == false) 
           { 
               return Action.ERROR; 
           } 
       }else{ 
           return Action.ERROR; 
       } 

        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
         System.out.println("Loi Update tbl_QLDTTXA_HocVien_HocPhi Action"); 
         e.printStackTrace(); 
         return Action.ERROR; 
 } 
 } 
 } 
 
